package com.spi.config;


import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class MyCustomerFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("before MyCustomerFilter");

//      SecurityContext emptyContext = SecurityContextHolder.createEmptyContext();
//      Authentication authentication = new TestingAuthenticationToken("username","password","ROLE_USER");
//      emptyContext.setAuthentication(authentication);
//      SecurityContextHolder.setContext(emptyContext);
        Authentication authentication = new TestingAuthenticationToken("username","password","ROLE_USER");
        SecurityContextHolder.getContext().setAuthentication(authentication);
        System.out.println("SecurityContext===" + SecurityContextHolder.getContext());
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("after MyCustomerFilter");
    }
}
